package com.atguigu.gmall.realtime.publisher.controller;


import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.realtime.publisher.bean.NameValueData;
import com.atguigu.gmall.realtime.publisher.service.DauService;
import com.atguigu.gmall.realtime.publisher.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class GmallController {

    @Autowired
    DauService dauService;

    @Autowired
    OrderService orderService;

    @GetMapping("/dauRealtime")
    public  String getDauRealtime(@RequestParam("td") String td){

        Map  dauMap=dauService.getDauMap(td);

        return JSON.toJSONString(dauMap);

    }

    @GetMapping("/statsByItem")
    public String  getStatsByItem(@RequestParam("t")String type ,
                                  @RequestParam("date")String date ,
                                  @RequestParam("itemName")String itemName  ){

         List<NameValueData>  nameValueDataList= orderService.getStatsByItem(type,date,itemName);

         return JSON.toJSONString(nameValueDataList);

    }

    @GetMapping("/detailByItem")
    public String getDetailByItem( @RequestParam("date")String date ,
                                  @RequestParam("itemName")String itemName,
                                   @RequestParam("pageNo") Integer pageNo,
                                   @RequestParam("pageSize")Integer pageSize ){
        Map  detailMap= orderService.getDetailByItem( date,itemName,pageNo,pageSize);

        return JSON.toJSONString(detailMap);


    }




}
